ProductDetailController = {
	
	init : function(data) {
		this.model = data;	
		this.view = ProductDetailView;	 
	},

    onClick : function(data) {
        if(data == "addToCart") {
            if(!CartController.checkItemInCart(this.model.BookDetail)) {
                CartController.addToCart(this.model.BookDetail);
                this.view.disableAddToCart();
            }
        } else if(data == "btnCmt") {
        	//event.preventDefault();
	  		var textbox = document.getElementById("txtCmt");
	  		var commentText = textbox.value;
	  		var bookId = textbox.getAttribute("bookid");
	  		var self = this;
	  		if(commentText){
				ajax.put({
		            url : "http://localhost:8080/book-service/public/book/store/comment/add",
		            param : {
		                "bookID" : bookId,
		                "comment":commentText
		            },
		            
		            success : function(data, xhr) {
		            	//console.log(data);
	            	 	var avatar = data.getElementsByTagName("userAvatar")[0].childNodes[0].nodeValue;
						var userName = data.getElementsByTagName("userName")[0].childNodes[0].nodeValue;
						var comment = data.getElementsByTagName("content")[0].childNodes[0].nodeValue;
						var createTime = data.getElementsByTagName("createTime")[0].childNodes[0].nodeValue;
						var commentModel = new Comment(avatar, userName, comment, createTime);
						createCommentNode(commentModel);
						self.view.updateScrollBar();
		            },
		            failure : function(xhr) {
		            	if(xhr.status==401){
		            		doPleaseLogin();
		            	}
		                console.log("fail");
		            },
		            abort : function(xhr) {
		                callback.abort(xhr);
		            }
		    	});
		    } else {
		    	alert("hãy nhập comment");
		    }
        } 
    }
};
